class Route < ActiveRecord::Base
	validates_presence_of :name
	has_many :routesite
	has_many :sites, :through => :routesite

	has_attachment :storage => :file_system, :path_prefix=>"public/route_files", :content_type => 'application/vnd.google-earth.kml+xml'
	validates_as_attachment

	def updateSiteRoute(site,order)
		myrs = Routesite.find(:first,:conditions => {:site_id => site, :route_id => self.id})
		if myrs.blank?
			Routesite.create() do |rs|
				rs.site_id = site
				rs.route_id = self.id
				rs.order = order
			end
		else
			myrs.order = order
			myrs.save
		end
	end

end
